import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom'
import { getToken } from 'utils/storage'
export default class index extends Component {
  render() {
    const { component: Component, ...res } = this.props
    return (
      <Route
        {...res}
        render={props => {
          if (getToken()) return <Component {...props} />
          return (
            <Redirect
              to={{
                pathname: '/login',
                state: { fromPath: props.location.pathname },
              }}
            />
          )
        }}
      />
    )
  }
}
